<template>
  <div>
    <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="userId"
          label="编号"
          width="80">
      </el-table-column>
      <el-table-column
          prop="account"
          label="用户名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="password"
          label="密码"
          width="120">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="120">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱"
          width="120">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="联系方式"
          width="120">
      </el-table-column>
      <el-table-column
          prop="question"
          label="密码问题"
          width="120">
      </el-table-column>
      <el-table-column
          prop="asw"
          label="问题答案"
          width="120">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="创建时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="updateTime"
          label="更新时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="age"
          label="年龄"
          width="120">
      </el-table-column>
      <el-table-column
          prop="sex"
          label="性别"
          width="120">
      </el-table-column>
      <el-table-column
          prop="del"
          label="删除状态"
          width="120">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="text" size="small">详情</el-button>
          <el-button type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        page-size="5"
        :total="total"
        @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    edit(row) {
      const _this=this;
      axios.post('http://localhost:8181/user/consumptionStatics/'+row.userId).then(function(resp){
        _this.$alert('该用户总消费金额为'+resp.data+'元', '总消费详情', {
          confirmButtonText: '确定',
          callback: action => {
            _this.$message({
              type: 'info',
              message: '详情已关闭'
            });
          }
        });
      })
    },
    page(currentPage){
      const _this=this;
      axios.get('http://localhost:8181/user/findAllAverageUsers/'+currentPage+'/'+5).then(function(resp){
        _this.tableData=resp.data.data
        _this.total=resp.data.totalNum
        _this.loading=false
      })
    }
  },
  created() {
    const _this=this;
    axios.get('http://localhost:8181/user/findAllAverageUsers/'+1+'/'+5).then(function(resp){
      _this.tableData=resp.data.data
      _this.total=resp.data.totalNum
      _this.loading=false
    })
  },
  data() {
    return {
      total:null,
      tableData:null,
      loading: true
    }
  }
}
</script>

<style scoped>

</style>